/*
 * Albareth - an action roleplaying game.
 * Copyright (C) 2008 Jens Anuth
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 *  02110-1301, USA.
 * 
 * $Id: Door.java 43 2008-05-13 16:52:12Z jens464 $
*/
package albareth.core.entity.item;

import albareth.core.entity.ActionItem;
import albareth.core.entity.Mobile;
import albareth.frontend.Tile;

public class Door extends ActionItem implements Cloneable
{
    private Tile _tileOpen;
    private Tile _tileClosed;
    private boolean _locked = false;

    public Door(String name, Tile tileClosed, Tile tileOpen, boolean locked)
    {
        super(name, tileClosed);
        _tileOpen = tileOpen;
        _tileClosed = tileClosed;
        setLocked(locked);
        setLockedDown(true);
        setUpperLayer(true);
        setClosed();
    }
    
    public Object clone() throws CloneNotSupportedException
    {
        return super.clone(); 
    }
    
    public boolean isLocked()
    {
        return _locked;
    }

    public void setLocked(boolean locked)
    {
        _locked = locked;
    }
    
    public void setClosed()
    {
        setTile(_tileClosed);
        setTranslucent(false);
        setBlocking(true);
    }

    public void setOpen()
    {
        setTile(_tileOpen);
        setTranslucent(true);
        setBlocking(false);
    }


    public boolean onActivate(Mobile src)
    {
        if (isLocked()) {
            src.infoMsg("The door is locked.");
            return true;
        }
        
        if (getTile() == _tileClosed)
        {
            src.eventMsg("You open the door.");
            setOpen();
        } else {
            src.eventMsg("You close the door.");
            setClosed();
        }
        return true;
    }

    public void enchant(int level)
    {
    }



}
